/**
 * @ClassName LC1816
 * @Author ykx
 * @Date 2024/3/20 16:02
 * @Version 1.0
 */
public class LC1816 {
    public String truncateSentence(String s, int k) {
        String[] strings = s.split(" ");
        StringBuilder result = new StringBuilder();
        for (int i = 0; i < strings.length; i++) {
            if (i >= k) {
                break;
            }
            result.append(" ").append(strings[i]);
        }
        return result.substring(1);
    }
}
